﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ColorClusteringSOM
{
    public class NeuronRough : Neuron
    {
        private String leaderName = "";
        private int leaderNumber = -1;

        //if leader  = false >> je v nejake dolni aproximaci
        private bool leader = false;

        private  Neuron neuron = null;

        private List<NeuronRough> lowerAppNeuronsArray = null;
        private List<NeuronRough> upperAppNeuronsArray = null;

        // toto je vahovy vektor leadru, ktery je jen pro vypocty presnych center!!!
        private double[] leaderWeight = null;

       
        


        #region Properties

        public double[] LeaderWeight { set { leaderWeight = value; } get { return leaderWeight; } }
        public Neuron Neuron { set { neuron = value; } get{ return neuron;}}
        

        public List<NeuronRough> UpperAppNeuronsArray
        {
            get { return this.upperAppNeuronsArray; }
        }
        public List<NeuronRough> LowerAppNeuronsArray
        {
            get { return this.lowerAppNeuronsArray; }
        }

        public String LeaderName
        {
            get { return this.leaderName; }
            set { this.leaderName = value; }
        }

        public int LeaderNumber
        {
            get { return this.leaderNumber; }
            set { this.leaderNumber = value; }
        }

        public bool Leader
        {
            get { return this.leader; }
            set { this.leader = value; }
        }

        
        #endregion


        public NeuronRough(Neuron neuron, bool leader)
        {
            this.neuron = neuron;
            this.leader = leader;
            this.X = neuron.X;
            this.Y = neuron.Y;


            if (leader)
            {
                lowerAppNeuronsArray = new List<NeuronRough>();
                upperAppNeuronsArray = new List<NeuronRough>();
                this.leaderWeight = new double[neuron.Weights.Length];
            }
            //else
            //{
            //    belongsToLeader = new List<NeuronRough>();
            //}
        }

        /// <summary>
        /// Konstrukto pro neuronRought
        /// zatim jen pro testovani
        /// 
        /// na konci se mu musi priradit nejaky odpovidajici neuron
        /// </summary>
        /// <param name="leader"></param>
        /// <param name="weightsLeader"></param>
        public NeuronRough(Neuron neuron,bool leader,double[] weightsLeader)
        {
            
            this.leader = leader;
            this.neuron = neuron;
            this.X = neuron.X;
            this.Y = neuron.Y;
            Console.WriteLine("Old X={0} Y={1}, NEW X={2} Y={3}",neuron.X,neuron.Y,this.X,this.Y);
            if (leader)
            {
                lowerAppNeuronsArray = new List<NeuronRough>();
                upperAppNeuronsArray = new List<NeuronRough>();
                leaderWeight = weightsLeader;
            }
        }


        /// <summary>
        /// Prida neuron v parametru do dolni aproximace leadra
        /// </summary>
        /// <param name="neuron"></param>
        public void AddToLowerApp(NeuronRough neuron)
        {
           
                this.lowerAppNeuronsArray.Add(neuron);
           
        }

        /// <summary>
        /// Prida neuron v parametru do horni aproximace leadra
        /// </summary>
        /// <param name="neuron"></param>
        public void AddToUpperApp(NeuronRough neuron)
        {
           
                this.upperAppNeuronsArray.Add(neuron);
           
        }

        public override string ToString()
        {
            String pom = String.Empty;
           
                pom += "\nLeader ["+ this.X+"," + this.Y+"]";
                pom += "\nCount LOWER =" + lowerAppNeuronsArray.Count + "\n";
                pom += "Count UPPER =" + upperAppNeuronsArray.Count + "\n";

                foreach (NeuronRough n in lowerAppNeuronsArray)
                {
                    pom += "neuron [" + n.X + "," + n.Y + "] \n";
                }

                

                

                foreach (NeuronRough n in upperAppNeuronsArray)
                {
                    pom += "neuron [" + n.X + "," + n.Y + "]\n";
                }
                
                return pom;
           
        }

    }

}
